package com.resource.gsLoader
{
	import com.greensock.events.LoaderEvent;
	import com.greensock.loading.LoaderMax;
	
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.utils.Dictionary;
	
	public class LoaderBase extends EventDispatcher
	{
		/**完成回调函数*/
		private var _completeFun:Function;
		/**进度回调函数*/
		private var _progressFun:Function;
		protected var _loader:LoaderMax;
		
		protected var _loadDic:Dictionary = new Dictionary();
		/**正在加载资源的数组*/
		protected var _loadingArr:Array ;
		/**已加载的相同资源数组,用于过滤*/
		protected var _resourceDic:Dictionary = new Dictionary();
		/**回调函数*/
		protected var _callBackDic:Dictionary = new Dictionary();
		
		private var _instance:LoaderBase;
		
		public function LoaderBase()
		{	
			_loader = new LoaderMax({onProgress:progressHandler,onComplete:completeHandler});	
		}
		
		
		protected function init():void
		{
		}
		
		
		/**
		 *加载中的方法
		 * */
		protected function progressHandler(e:LoaderEvent):void
		{
			if (_progressFun != null) 
			{
				_progressFun(e);
			}
			
		}
		
		
		/**
		 * 全部加载完成时的方法
		 * */
		protected function completeHandler(e:LoaderEvent):void
		{
			if (_completeFun != null) 
			{
				_completeFun();
			}	
			
		}
		
		
		/**
		 * 多资源加载
		 * arr[[url,completeFun],[url,completeFun].....] 
		 * url - 地址
		 * completeFun - 完成的回调函数
		 * */
		public function loadMultiple(arr:Array):void
		{
			
		}
		
		
		/**
		 * 单资源加载
		 * url - 地址
		 * fun - 回调函数
		 * */
		public function load(url:String,fun:Function):void
		{
			
		}
		
		
		/**
		 * 设置进度回调函数
		 * @param value
		 */
		public function set progress(value:Function):void
		{
			if (value != null) 
			{
				_progressFun = value;
			}		
		}
		
		
		/**
		 * 设置完成回调函数
		 * @param value
		 */
		public function set complete(value:Function):void
		{
			if (value != null) 
			{
				_completeFun = value;
			}	
		}
		
		/**
		 * 
		 * @return 
		 */
		public function get loader():LoaderMax
		{
			return _loader;
		}
		
		
		public function removeLoader(name:String):void
		{
			if (!name || name=="") 
			{
				return;
			}
			_loader.remove(_loader.getLoader(name));
		}
	}
}